# -*- coding: UTF-8 -*-
# server_assets
# @File : CharacterLevel.py
# @Date : 2023-08-25
# @Author  : wuzhouhai
# @Desc:
import KBEngine
from KBEDebug import *

class CharacterLevel:

    def __init__(self):
        pass

    def setCyLevel(self, cyLevel):
        """设置角色阶级"""
        self._cyLevel = cyLevel

    def getCyLevel(self):
        """获取角色阶级"""
        return self._cyLevel

    def getCyLevelInfo(self):
        """获取角色阶级信息"""
        return {}
        # return dbCharacter.CHARACTER_CYLEVEL_INFO.get(self._owner.profession.getProfession(), {}).get(self._cyLevel, {})

    def setVipLevel(self, level):
        """初始化VIP等级
        """
        # oldLevel = self._vipLevel
        self._vipLevel = level
        # self._owner.task.updateTaskConditionValue(dbTask.TASK_CONDITION_VIPLEVEL, self._vipLevel)
        # if isSync:
        #     self._owner.updateVipLevelSystem(oldLevel, self._vipLevel)
        #     self._owner.SyncRoleVip()

    def updateVipLevel(self, level):
        """更新VIP等级"""
        if self._vipLevel >= level:
            return
        # oldLevel = self._vipLevel
        self._vipLevel = level
        # self._owner.task.updateTaskConditionValue(dbTask.TASK_CONDITION_VIPLEVEL, self._vipLevel)
        # self._owner.updateVipLevelSystem(oldLevel, self._vipLevel)
        # self._owner.SyncRoleVip()

    def getVipLevel(self):
        """获取VIP等级
        """
        return self._vipLevel

    def getMaxVipExp(self):
        """获取当前最大VIP经验"""
        # return vipManager.GetVipLevelExp(self._vipLevel)
        return 0

    def updateVipExp(self, exp, state=1, update=1):
        """更新角色VIP经验值
        @param exp: int 经验值
        @param status: int 表示是否及时推送升级消息
        """
        oldLevel = self._vipLevel
        if exp == self._vipExp:
            return
        if self._vipLevel >= self.MAXVIP:
            return
        self._vipExp = exp
        while self.getMaxVipExp() and self._vipExp >= self.getMaxVipExp():
            self._vipExp -= self.getMaxVipExp()
            self._vipLevel += 1
            if self._vipLevel >= self.MAXVIP:
                self._vipExp = 0
                break

        if not self.getMaxVipExp():
            self._vipExp = 0
        # if oldLevel != self._vipLevel:  # 等级变化，更新信息
        #     self._owner.updateVipLevelSystem(oldLevel, self._vipLevel)
        #     self._owner.task.updateTaskConditionValue(dbTask.TASK_CONDITION_VIPLEVEL, self._vipLevel)
        #
        # self._owner.SyncRoleVip()

    def addVipExp(self, exp, state=1, update=1):
        """加经验"""
        self.updateVipExp(exp + self.getVipExp(), state=state, update=update)

    def getVipExp(self):
        """获取角色当前VIP经验
        """
        return self._vipExp

    def setVipExp(self, exp):
        """设置角色当前VIP经验值
        @param exp: int 经验值
        """
        self._vipExp = exp

    def getMaxExp(self):
        """计算当前级别的最大经验值"""
        # expinfo = dbExperience.tb_Experience_config.get(self._level, {})
        # maxExp = expinfo.get('exp',
        #                      0)  # 400 + 60 * (self._level - 1) + 10 * self._level * (self._level + 1) * (self._level - 1)
        return 0

    def getExp(self):
        """获取角色当前经验
        """
        return self._exp

    def setExp(self, exp):
        """设置角色当前经验值
        @param exp: int 经验值
        """
        self._exp = exp

    def updateExp(self, exp, state=1, update=1):
        """更新角色经验值
        @param exp: int 经验值
        @param status: int 表示是否及时推送升级消息
        """
        oldLevel = self._level
        if exp == self._exp:
            return
        if self._level >= self.MAXLEVEL:
            return
        self._exp = exp
        # while self._exp >= self.getMaxExp() and self._level < self.MAXLEVEL:
        #     self._exp -= self.getMaxExp()
        #     self._level += 1
        #     if self._level == dbGameConfig.SYSTEM_OPEN_LEVEL_WING:
        #         self._owner.wing.newFirstWing()
        #     if self._level == dbGameConfig.SYSTEM_OPEN_AREA:
        #         self._owner.arena.initArena()
        #     if self._level == dbGameConfig.SYSTEM_OPEN_LEVEL_HLEPOUT:
        #         self._owner.matrix.initHelpOut()
        #     if self._level == self.MAXLEVEL:
        #         self._exp = 0
        #
        # if oldLevel != self._level:  # 等级变化，更新角色信息
        #     # self._owner.updateCharacterSkills()#更新技能
        #     #             self._owner.updateCharacterActivePet()#检测元神开启
        #     self._owner.updateCharacterAttribute()  # 更新装备
        #     self._owner.updateCharacterPet()  # 更新元神
        #     self._owner.SyncRoleLevel()
        #     self._owner.task.acceptAllTask()
        #     pmmode = tb_character_admin.getObj(self._owner.baseInfo.getId())
        #     pmmode.update('level', self._level)
        #     self._owner.task.updateTaskConditionValue(dbTask.TASK_CONDITION_LEVEL, self._level)
        #
        # self._owner.SyncRoleExp()

    def addExp(self, exp, state=1, update=1):
        """加经验"""
        if exp < 0:
            return
        self.updateExp(exp + self.getExp(), state=state, update=update)

    def getLevel(self):
        """获取角色当前等级
        """
        return self._level

    def setLevel(self, level):
        """设置角色当前等级
        @param level: int 等级
        """
        self._level = level

    def updateLevel(self, level):
        """更新等级"""
        self.setLevel(level)
        # self._owner.SyncRoleLevel()
        # self._owner.updateCharacterAttribute()
        # self._owner.updateCharacterSkills()#更新技能

    def updateTask(self):
        """更新任务"""
        # self._owner.task.updateTaskConditionValue(dbTask.TASK_CONDITION_LEVEL, self._level)
        # self._owner.task.updateTaskConditionValue(dbTask.TASK_CONDITION_VIPLEVEL, self._vipLevel)
        pass